package org.zjt.config.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zjt.config.operation.UnifiedConfigOperation;
import org.zjt.config.properties.RemotePropertiesHolder;

/**
 * @author <a href="juntao.zhang@bkjk.com">juntao.zhang</a>
 * @Description:
 * @Package com.example.config.controller
 * @date 2017/12/13 15:24
 * @see
 */
@RestController
public class TestController implements EnvironmentAware{

    @Value("${zhang.age:24}")
    private Integer name;

    public Integer getName() {
        return name;
    }

    @Value("${zhang.age:24}")
    public void setName(Integer name) {
        this.name = name;
    }

    @Autowired
    private UnifiedConfigOperation unifiedConfigOperation;

    @GetMapping("/name")
    public void main(String[] args) {
        RemotePropertiesHolder.keys.forEach(item ->{
            System.out.println(item +" -> "+this.environment.getProperty(item));
        });
        System.out.println(name);
        System.err.println(unifiedConfigOperation);
    }

    private Environment environment;
    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
